<?php
class TransinsController extends AppController {       

    public $helpers = array('Html', 'Form');
    public $components = array('Session');
    public $uses = array('Division', 'Union', 'Region','District');

    public function index() {
        $pageTitle ="Seventh-day Adventist Church - Kwabrafoso: Transfer In";
        $in_record_data = $this->Transin->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }

    
    public function add(){
    $regionlist = $this->Region->find('all');
    $division = $this->Division->find('all');
    $union = $this->Union->find('all');
  //  $conference = $this->Conference->find('all');
  //  $countrie = $this->Countrie->find('all');
    $district = $this->District->find('all');
    
    $pageTitle ="Worldwide SDA Church - Kwabrafoso: Add Transfer In";
     if($_POST){
       // pr($_POST);
        $data['Transin'] = array(
            'transinid' => $_POST['transinid'],
            'mshipno' => $_POST['mshipno'],
            'name' => $_POST['name'],
            'transdate' => $_POST['transdate'],
            'divname' => $_POST['divname'],
            'uniname' => $_POST['uniname'],
            'country' => $_POST['country'],
            'confname' => $_POST['confname'],
            'regname' => $_POST['regname'],
            'distname' => $_POST['distname'],
            'town' => $_POST['town'],
            'chuname' => $_POST['chuname'],
            'buzmeetingno' => $_POST['buzmeetingno']
        );

        if(!$this->Transin->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg','regionlist','districtlist'));
}
    
    // A functin to delete Records
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Record');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Transin->delete($id)) 
    {
        $this->Session->setFlash('Record Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Record Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Records
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Transin.id' => $record_id);
    $record = $this->Transin->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="SDA Church - Kwabrafoso: Edit Transfers";
     if($_POST){
        //pr($_POST);
        $data['Transin'] = array(
            'transinid' => $_POST['transinid'],
            'mshipno' => $_POST['mshipno'],
            'name' => $_POST['name'],
            'transdate' => $_POST['transdate'],
            'divname' => $_POST['divname'],
            'uniname' => $_POST['uniname'],
            'country' => $_POST['country'],
            'confname' => $_POST['confname'],
            'regname' => $_POST['regname'],
            'distname' => $_POST['distname'],
            'town' => $_POST['town'],
            'chuname' => $_POST['chuname'],
            'buzmeetingno' => $_POST['buzmeetingno']
        );

        if(!$this->Transin->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Transfers
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $transin = $this->Transin->findById($id);
    if (!$transin) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('transin', $transin);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('Transin.id' => $record_id);
    $record = $this->Transin->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>
